package com.nondo.dean.dealer.controller.api.app;

import com.nondo.dean.common.annotation.ApiVersion;
import com.nondo.dean.common.web.View;
import com.nondo.dean.dealer.domain.ActivityTemplate;
import com.nondo.dean.dealer.service.ActivityTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author xiaofan
 * @Description: 模板管理
 * @throws
 * @date 2018-05-0911:51
 * @Version 0.1
 */
@RestController("apiAppDealerActivityTemplate")
@RequestMapping("/{v}/app/activity/template")
public class ActivityTemplateController {

    @Autowired
    ActivityTemplateService activityTemplateService;


    /**
     * 查询所有模板列表
     * @return
     */
    @ApiVersion(1)
    @RequestMapping("/list")
    public View<List<ActivityTemplate>> List(){
        View<List<ActivityTemplate>> view = new View<List<ActivityTemplate>>(20000, "获取数据成功");

        List<ActivityTemplate> list = activityTemplateService.selectList();

        view.setData(list);

        return view;
    }

    /**
     * 查看模板
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping("/info/{id}")
    public ModelAndView queryTemplate(HttpServletRequest request, HttpServletResponse response, @PathVariable("id") Integer id) {
        ActivityTemplate beans=activityTemplateService.select(id);
        if(beans == null){
            beans = new ActivityTemplate();
        }
        ModelAndView mv = new ModelAndView("wap/app/template/template");

        mv.addObject("template", beans);
        return mv;
    }
}
